package com.zrrd.gmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zrrd.gmall.model.user.UserInfo;
import com.zrrd.gmall.user.mapper.UserInfoMapper;
import com.zrrd.gmall.user.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class UserServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserService {
    @Override
    public UserInfo login(UserInfo userInfo) {
        //获取传递来的密码
        String passwd = userInfo.getPasswd();
        //将密码加密
        passwd = DigestUtils.md5DigestAsHex(passwd.getBytes());
        //条件构造器查询
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("login_name",userInfo.getLoginName());
        wrapper.eq("passwd",passwd);
        UserInfo info = this.getOne(wrapper);
        return info;
    }
}
